package servlet;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import entity.User;
import session.UserDao;

 
/**
 * Kontroler koji priprema podatke za
 * unactiveUsers.jsp
 * koji su potrebni za listiranje neaktiviranih korisnika.
 * 
 * @author rigo & jung
 *
 */
public class PrepareUnactiveUsers extends HttpServlet {
	private static final long serialVersionUID = 531395085730230215L;
	
	@EJB
	protected UserDao userDao ;
	 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		try{
			
			User admin;
			if((admin = (User)request.getSession().getAttribute("user"))==null ||
					admin.getType()!='A'){
				response.sendRedirect(response.encodeURL("./login.jsp"));
				return;
			}
				request.setAttribute("pendingUsers", userDao.getPendingUsers());
				getServletContext().getRequestDispatcher("/unactiveUsers.jsp").forward(request, response);
				return;
		}catch (Exception e) {
			e.printStackTrace();
		}
		response.sendRedirect(response.encodeRedirectURL("./login.jsp"));
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
